package com.weilai.dao;

import com.weilai.domain.Drafts;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DraftDao {
    @Select("SELECT * FROM drafts WHERE post_id=#{postId}")
    public Drafts selectByPostId(int postId);

    @Select("SELECT * FROM drafts WHERE user_id=#{userId}")
    public List<Drafts> selectByUserId(int userId);

    @Insert("INSERT INTO drafts (user_id,post_id, type, title, content, category_id, category_name,imageUrl) " +
            "VALUES (#{userId},#{postId}, #{type}, #{title}, #{content}, #{categoryId}, #{categoryName}, #{imageUrl})")
    public void addDrafts(Drafts drafts);

    @Update("UPDATE drafts SET type=#{type}, title=#{title}, " +
            "content=#{content}, category_id=#{categoryId}, category_name=#{categoryName},imageUrl=#{imageUrl} " +
            "WHERE postId = #{postId}")
    public void updateDrafts(Drafts drafts);

    // 按 userid 删除草稿
    @Delete("DELETE FROM drafts WHERE user_id = #{userId}")
    void deleteUserById(int userId);
}